﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DroidClaim.Web.Mapper;
using DroidClaim.Web.Models;
using DroidClaim.Web.Service;
using DroidClaim.Web.Utilities;

namespace DroidClaim.Web.Controllers
{
    public class PopupController : Controller
    {
		
		#region ClaimInfo_ClaimStatus lookup
        /* Summary
         * 1 lookup attribute has 4 method in controller
         * 
         * 1. XXXGetLookup() -> get value from search key
         * 2. XXXPopLookup() -> popup the lookup page for user selection.
         *    It will feed the model to the popup View that has the same name.
         *    (Each lookup has it own popup View)
         * 3. GetXXXForKey(string key) -> get 
         */
        public String ClaimInfo_ClaimStatusGetLookup()
        {
            ClaimStatusModel model = new ClaimStatusModel();
            if (Request.QueryString["searchKey"] != null)
            {
                List<ClaimStatusModel> ClaimStatus = this.ClaimInfo_GetClaimStatusForKey(Request.QueryString["searchKey"]);
                if (ClaimStatus.Count == 1)
                {
                    String ClaimStatusStr;
                    foreach (var item in ClaimStatus)
                    {
                        ClaimStatusStr = String.Concat(item.Id.ToString(), "|", item.Code, "|", item.Name);
                        return ClaimStatusStr;
                    }

                }
                else if (ClaimStatus.Count > 1)
                {
                    return "MoreOne";
                }
            }
            return "NotFound";
        }

        public ActionResult ClaimInfo_ClaimStatusPopLookup()
        {
            ClaimStatusModel model = new ClaimStatusModel();
            if (Request.QueryString["searchKey"] != null)
            {
                model.ListOfClaimStatus = this.ClaimInfo_GetClaimStatusForKey(Request.QueryString["searchKey"]);
            }
            else
            {
                model.ListOfClaimStatus = this.ClaimInfo_GetClaimStatusAll();
            }
            return View(model);
        }

        private List<ClaimStatusModel> ClaimInfo_GetClaimStatusForKey(String key)
        {

            var result = new List<ClaimStatusModel>();
            var service = new ServiceClient();
            GetAllClaimStatusRequestDto gAllreq = new GetAllClaimStatusRequestDto
            {
                Code = key
            };
            var list = service.GetAllClaimStatus(gAllreq);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					result.Add(ClaimStatusMapper.DtoToModel(item));
                }
            }
            return result;
        }

        private List<ClaimStatusModel> ClaimInfo_GetClaimStatusAll()
        {
            return ClaimInfo_GetClaimStatusAll(null);
        }

        private List<ClaimStatusModel> ClaimInfo_GetClaimStatusAll(string searchValue)
        {
            var result = new List<ClaimStatusModel>();
            var service = new ServiceClient();
            GetAllClaimStatusRequestDto request = null;
            if (!String.IsNullOrEmpty(searchValue))
            {
                request = new GetAllClaimStatusRequestDto()
                {
													
																			
													Name = searchValue,
																			
													Code = searchValue,
											
                    Sort = "Code", // ยังไม่ได้เปลี่ยนให้ Auto
                    SortType = "ASC",
                };
            }
            var list = service.GetAllClaimStatus(request);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					 result.Add(ClaimStatusMapper.DtoToModel(item));
                }
            }
            return result;
        }
        #endregion

		
		#region ClaimInfo_CliamDoc lookup
        /* Summary
         * 1 lookup attribute has 4 method in controller
         * 
         * 1. XXXGetLookup() -> get value from search key
         * 2. XXXPopLookup() -> popup the lookup page for user selection.
         *    It will feed the model to the popup View that has the same name.
         *    (Each lookup has it own popup View)
         * 3. GetXXXForKey(string key) -> get 
         */
        public String ClaimInfo_CliamDocGetLookup()
        {
            CliamDocModel model = new CliamDocModel();
            if (Request.QueryString["searchKey"] != null)
            {
                List<CliamDocModel> CliamDoc = this.ClaimInfo_GetCliamDocForKey(Request.QueryString["searchKey"]);
                if (CliamDoc.Count == 1)
                {
                    String CliamDocStr;
                    foreach (var item in CliamDoc)
                    {
                        CliamDocStr = String.Concat(item.Id.ToString(), "|", item.Code, "|", item.Name);
                        return CliamDocStr;
                    }

                }
                else if (CliamDoc.Count > 1)
                {
                    return "MoreOne";
                }
            }
            return "NotFound";
        }

        public ActionResult ClaimInfo_CliamDocPopLookup()
        {
            CliamDocModel model = new CliamDocModel();
            if (Request.QueryString["searchKey"] != null)
            {
                model.ListOfCliamDoc = this.ClaimInfo_GetCliamDocForKey(Request.QueryString["searchKey"]);
            }
            else
            {
                model.ListOfCliamDoc = this.ClaimInfo_GetCliamDocAll();
            }
            return View(model);
        }

        private List<CliamDocModel> ClaimInfo_GetCliamDocForKey(String key)
        {

            var result = new List<CliamDocModel>();
            var service = new ServiceClient();
            GetAllCliamDocRequestDto gAllreq = new GetAllCliamDocRequestDto
            {
                Code = key
            };
            var list = service.GetAllCliamDoc(gAllreq);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					result.Add(CliamDocMapper.DtoToModel(item));
                }
            }
            return result;
        }

        private List<CliamDocModel> ClaimInfo_GetCliamDocAll()
        {
            return ClaimInfo_GetCliamDocAll(null);
        }

        private List<CliamDocModel> ClaimInfo_GetCliamDocAll(string searchValue)
        {
            var result = new List<CliamDocModel>();
            var service = new ServiceClient();
            GetAllCliamDocRequestDto request = null;
            if (!String.IsNullOrEmpty(searchValue))
            {
                request = new GetAllCliamDocRequestDto()
                {
													
																			
																			
													Code = searchValue,
																			
													Name = searchValue,
											
                    Sort = "Code", // ยังไม่ได้เปลี่ยนให้ Auto
                    SortType = "ASC",
                };
            }
            var list = service.GetAllCliamDoc(request);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					 result.Add(CliamDocMapper.DtoToModel(item));
                }
            }
            return result;
        }
        #endregion

		
		#region ClaimInfo_Customer lookup
        /* Summary
         * 1 lookup attribute has 4 method in controller
         * 
         * 1. XXXGetLookup() -> get value from search key
         * 2. XXXPopLookup() -> popup the lookup page for user selection.
         *    It will feed the model to the popup View that has the same name.
         *    (Each lookup has it own popup View)
         * 3. GetXXXForKey(string key) -> get 
         */
        public String ClaimInfo_CustomerGetLookup()
        {
            CustomerModel model = new CustomerModel();
            if (Request.QueryString["searchKey"] != null)
            {
                List<CustomerModel> Customer = this.ClaimInfo_GetCustomerForKey(Request.QueryString["searchKey"]);
                if (Customer.Count == 1)
                {
                    String CustomerStr;
                    foreach (var item in Customer)
                    {
                        CustomerStr = String.Concat(item.Id.ToString(), "|", item.Code, "|", item.Name);
                        return CustomerStr;
                    }

                }
                else if (Customer.Count > 1)
                {
                    return "MoreOne";
                }
            }
            return "NotFound";
        }

        public ActionResult ClaimInfo_CustomerPopLookup()
        {
            CustomerModel model = new CustomerModel();
            if (Request.QueryString["searchKey"] != null)
            {
                model.ListOfCustomer = this.ClaimInfo_GetCustomerForKey(Request.QueryString["searchKey"]);
            }
            else
            {
                model.ListOfCustomer = this.ClaimInfo_GetCustomerAll();
            }
            return View(model);
        }

        private List<CustomerModel> ClaimInfo_GetCustomerForKey(String key)
        {

            var result = new List<CustomerModel>();
            var service = new ServiceClient();
            GetAllCustomerRequestDto gAllreq = new GetAllCustomerRequestDto
            {
                Code = key
            };
            var list = service.GetAllCustomer(gAllreq);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					result.Add(CustomerMapper.DtoToModel(item));
                }
            }
            return result;
        }

        private List<CustomerModel> ClaimInfo_GetCustomerAll()
        {
            return ClaimInfo_GetCustomerAll(null);
        }

        private List<CustomerModel> ClaimInfo_GetCustomerAll(string searchValue)
        {
            var result = new List<CustomerModel>();
            var service = new ServiceClient();
            GetAllCustomerRequestDto request = null;
            if (!String.IsNullOrEmpty(searchValue))
            {
                request = new GetAllCustomerRequestDto()
                {
													
																			
																			
																			
													Name = searchValue,
																			
																			
																			
																			
																			
																			
																			
																			
																			
																			
													Code = searchValue,
											
                    Sort = "Code", // ยังไม่ได้เปลี่ยนให้ Auto
                    SortType = "ASC",
                };
            }
            var list = service.GetAllCustomer(request);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					 result.Add(CustomerMapper.DtoToModel(item));
                }
            }
            return result;
        }
        #endregion

		
		#region ClaimInfo_Surveyor lookup
        /* Summary
         * 1 lookup attribute has 4 method in controller
         * 
         * 1. XXXGetLookup() -> get value from search key
         * 2. XXXPopLookup() -> popup the lookup page for user selection.
         *    It will feed the model to the popup View that has the same name.
         *    (Each lookup has it own popup View)
         * 3. GetXXXForKey(string key) -> get 
         */
        public String ClaimInfo_SurveyorGetLookup()
        {
            SurveyorModel model = new SurveyorModel();
            if (Request.QueryString["searchKey"] != null)
            {
                List<SurveyorModel> Surveyor = this.ClaimInfo_GetSurveyorForKey(Request.QueryString["searchKey"]);
                if (Surveyor.Count == 1)
                {
                    String SurveyorStr;
                    foreach (var item in Surveyor)
                    {
                        SurveyorStr = String.Concat(item.Id.ToString(), "|", item.Code, "|", item.Name);
                        return SurveyorStr;
                    }

                }
                else if (Surveyor.Count > 1)
                {
                    return "MoreOne";
                }
            }
            return "NotFound";
        }

        public ActionResult ClaimInfo_SurveyorPopLookup()
        {
            SurveyorModel model = new SurveyorModel();
            if (Request.QueryString["searchKey"] != null)
            {
                model.ListOfSurveyor = this.ClaimInfo_GetSurveyorForKey(Request.QueryString["searchKey"]);
            }
            else
            {
                model.ListOfSurveyor = this.ClaimInfo_GetSurveyorAll();
            }
            return View(model);
        }

        private List<SurveyorModel> ClaimInfo_GetSurveyorForKey(String key)
        {

            var result = new List<SurveyorModel>();
            var service = new ServiceClient();
            GetAllSurveyorRequestDto gAllreq = new GetAllSurveyorRequestDto
            {
                Code = key
            };
            var list = service.GetAllSurveyor(gAllreq);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					result.Add(SurveyorMapper.DtoToModel(item));
                }
            }
            return result;
        }

        private List<SurveyorModel> ClaimInfo_GetSurveyorAll()
        {
            return ClaimInfo_GetSurveyorAll(null);
        }

        private List<SurveyorModel> ClaimInfo_GetSurveyorAll(string searchValue)
        {
            var result = new List<SurveyorModel>();
            var service = new ServiceClient();
            GetAllSurveyorRequestDto request = null;
            if (!String.IsNullOrEmpty(searchValue))
            {
                request = new GetAllSurveyorRequestDto()
                {
													
																			
																			
																			
																			
																			
													Name = searchValue,
																			
																			
																			
																			
																			
													Code = searchValue,
																			
											
                    Sort = "Code", // ยังไม่ได้เปลี่ยนให้ Auto
                    SortType = "ASC",
                };
            }
            var list = service.GetAllSurveyor(request);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					 result.Add(SurveyorMapper.DtoToModel(item));
                }
            }
            return result;
        }
        #endregion

		
		#region ClaimInfo_ClaimNumber lookup
        /* Summary
         * 1 lookup attribute has 4 method in controller
         * 
         * 1. XXXGetLookup() -> get value from search key
         * 2. XXXPopLookup() -> popup the lookup page for user selection.
         *    It will feed the model to the popup View that has the same name.
         *    (Each lookup has it own popup View)
         * 3. GetXXXForKey(string key) -> get 
         */
        public String ClaimInfo_ClaimNumberGetLookup()
        {
            ClaimNumberModel model = new ClaimNumberModel();
            if (Request.QueryString["searchKey"] != null)
            {
                List<ClaimNumberModel> ClaimNumber = this.ClaimInfo_GetClaimNumberForKey(Request.QueryString["searchKey"]);
                if (ClaimNumber.Count == 1)
                {
                    String ClaimNumberStr;
                    foreach (var item in ClaimNumber)
                    {
                        ClaimNumberStr = String.Concat(item.Id.ToString(), "|", item.Code, "|", item.Name);
                        return ClaimNumberStr;
                    }

                }
                else if (ClaimNumber.Count > 1)
                {
                    return "MoreOne";
                }
            }
            return "NotFound";
        }

        public ActionResult ClaimInfo_ClaimNumberPopLookup()
        {
            ClaimNumberModel model = new ClaimNumberModel();
            if (Request.QueryString["searchKey"] != null)
            {
                model.ListOfClaimNumber = this.ClaimInfo_GetClaimNumberForKey(Request.QueryString["searchKey"]);
            }
            else
            {
                model.ListOfClaimNumber = this.ClaimInfo_GetClaimNumberAll();
            }
            return View(model);
        }

        private List<ClaimNumberModel> ClaimInfo_GetClaimNumberForKey(String key)
        {

            var result = new List<ClaimNumberModel>();
            var service = new ServiceClient();
            GetAllClaimNumberRequestDto gAllreq = new GetAllClaimNumberRequestDto
            {
                Code = key
            };
            var list = service.GetAllClaimNumber(gAllreq);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					result.Add(ClaimNumberMapper.DtoToModel(item));
                }
            }
            return result;
        }

        private List<ClaimNumberModel> ClaimInfo_GetClaimNumberAll()
        {
            return ClaimInfo_GetClaimNumberAll(null);
        }

        private List<ClaimNumberModel> ClaimInfo_GetClaimNumberAll(string searchValue)
        {
            var result = new List<ClaimNumberModel>();
            var service = new ServiceClient();
            GetAllClaimNumberRequestDto request = null;
            if (!String.IsNullOrEmpty(searchValue))
            {
                request = new GetAllClaimNumberRequestDto()
                {
													
																			
													Code = searchValue,
																			
													Name = searchValue,
											
                    Sort = "Code", // ยังไม่ได้เปลี่ยนให้ Auto
                    SortType = "ASC",
                };
            }
            var list = service.GetAllClaimNumber(request);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					 result.Add(ClaimNumberMapper.DtoToModel(item));
                }
            }
            return result;
        }
        #endregion

		
		#region RejectedHistory_ClaimInfo lookup
        /* Summary
         * 1 lookup attribute has 4 method in controller
         * 
         * 1. XXXGetLookup() -> get value from search key
         * 2. XXXPopLookup() -> popup the lookup page for user selection.
         *    It will feed the model to the popup View that has the same name.
         *    (Each lookup has it own popup View)
         * 3. GetXXXForKey(string key) -> get 
         */
        public String RejectedHistory_ClaimInfoGetLookup()
        {
            ClaimInfoModel model = new ClaimInfoModel();
            if (Request.QueryString["searchKey"] != null)
            {
                List<ClaimInfoModel> ClaimInfo = this.RejectedHistory_GetClaimInfoForKey(Request.QueryString["searchKey"]);
                if (ClaimInfo.Count == 1)
                {
                    String ClaimInfoStr;
                    foreach (var item in ClaimInfo)
                    {
                        ClaimInfoStr = String.Concat(item.Id.ToString(), "|", item.Code, "|", item.Name);
                        return ClaimInfoStr;
                    }

                }
                else if (ClaimInfo.Count > 1)
                {
                    return "MoreOne";
                }
            }
            return "NotFound";
        }

        public ActionResult RejectedHistory_ClaimInfoPopLookup()
        {
            ClaimInfoModel model = new ClaimInfoModel();
            if (Request.QueryString["searchKey"] != null)
            {
                model.ListOfClaimInfo = this.RejectedHistory_GetClaimInfoForKey(Request.QueryString["searchKey"]);
            }
            else
            {
                model.ListOfClaimInfo = this.RejectedHistory_GetClaimInfoAll();
            }
            return View(model);
        }

        private List<ClaimInfoModel> RejectedHistory_GetClaimInfoForKey(String key)
        {

            var result = new List<ClaimInfoModel>();
            var service = new ServiceClient();
            GetAllClaimInfoRequestDto gAllreq = new GetAllClaimInfoRequestDto
            {
                Code = key
            };
            var list = service.GetAllClaimInfo(gAllreq);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					result.Add(ClaimInfoMapper.DtoToModel(item));
                }
            }
            return result;
        }

        private List<ClaimInfoModel> RejectedHistory_GetClaimInfoAll()
        {
            return RejectedHistory_GetClaimInfoAll(null);
        }

        private List<ClaimInfoModel> RejectedHistory_GetClaimInfoAll(string searchValue)
        {
            var result = new List<ClaimInfoModel>();
            var service = new ServiceClient();
            GetAllClaimInfoRequestDto request = null;
            if (!String.IsNullOrEmpty(searchValue))
            {
                request = new GetAllClaimInfoRequestDto()
                {
													
																			
																			
																			
																			
																			
																			
																			
																			
																			
																			
																			
																			
													Code = searchValue,
																			
													Name = searchValue,
																			
											
                    Sort = "Code", // ยังไม่ได้เปลี่ยนให้ Auto
                    SortType = "ASC",
                };
            }
            var list = service.GetAllClaimInfo(request);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					 result.Add(ClaimInfoMapper.DtoToModel(item));
                }
            }
            return result;
        }
        #endregion

		
		#region RejectedHistory_Surveyor lookup
        /* Summary
         * 1 lookup attribute has 4 method in controller
         * 
         * 1. XXXGetLookup() -> get value from search key
         * 2. XXXPopLookup() -> popup the lookup page for user selection.
         *    It will feed the model to the popup View that has the same name.
         *    (Each lookup has it own popup View)
         * 3. GetXXXForKey(string key) -> get 
         */
        public String RejectedHistory_SurveyorGetLookup()
        {
            SurveyorModel model = new SurveyorModel();
            if (Request.QueryString["searchKey"] != null)
            {
                List<SurveyorModel> Surveyor = this.RejectedHistory_GetSurveyorForKey(Request.QueryString["searchKey"]);
                if (Surveyor.Count == 1)
                {
                    String SurveyorStr;
                    foreach (var item in Surveyor)
                    {
                        SurveyorStr = String.Concat(item.Id.ToString(), "|", item.Code, "|", item.Name);
                        return SurveyorStr;
                    }

                }
                else if (Surveyor.Count > 1)
                {
                    return "MoreOne";
                }
            }
            return "NotFound";
        }

        public ActionResult RejectedHistory_SurveyorPopLookup()
        {
            SurveyorModel model = new SurveyorModel();
            if (Request.QueryString["searchKey"] != null)
            {
                model.ListOfSurveyor = this.RejectedHistory_GetSurveyorForKey(Request.QueryString["searchKey"]);
            }
            else
            {
                model.ListOfSurveyor = this.RejectedHistory_GetSurveyorAll();
            }
            return View(model);
        }

        private List<SurveyorModel> RejectedHistory_GetSurveyorForKey(String key)
        {

            var result = new List<SurveyorModel>();
            var service = new ServiceClient();
            GetAllSurveyorRequestDto gAllreq = new GetAllSurveyorRequestDto
            {
                Code = key
            };
            var list = service.GetAllSurveyor(gAllreq);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					result.Add(SurveyorMapper.DtoToModel(item));
                }
            }
            return result;
        }

        private List<SurveyorModel> RejectedHistory_GetSurveyorAll()
        {
            return RejectedHistory_GetSurveyorAll(null);
        }

        private List<SurveyorModel> RejectedHistory_GetSurveyorAll(string searchValue)
        {
            var result = new List<SurveyorModel>();
            var service = new ServiceClient();
            GetAllSurveyorRequestDto request = null;
            if (!String.IsNullOrEmpty(searchValue))
            {
                request = new GetAllSurveyorRequestDto()
                {
													
																			
																			
																			
																			
																			
													Name = searchValue,
																			
																			
																			
																			
																			
													Code = searchValue,
																			
											
                    Sort = "Code", // ยังไม่ได้เปลี่ยนให้ Auto
                    SortType = "ASC",
                };
            }
            var list = service.GetAllSurveyor(request);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					 result.Add(SurveyorMapper.DtoToModel(item));
                }
            }
            return result;
        }
        #endregion

		
		#region Surveyor_SurveyorLocation lookup
        /* Summary
         * 1 lookup attribute has 4 method in controller
         * 
         * 1. XXXGetLookup() -> get value from search key
         * 2. XXXPopLookup() -> popup the lookup page for user selection.
         *    It will feed the model to the popup View that has the same name.
         *    (Each lookup has it own popup View)
         * 3. GetXXXForKey(string key) -> get 
         */
        public String Surveyor_SurveyorLocationGetLookup()
        {
            SurveyorLocationModel model = new SurveyorLocationModel();
            if (Request.QueryString["searchKey"] != null)
            {
                List<SurveyorLocationModel> SurveyorLocation = this.Surveyor_GetSurveyorLocationForKey(Request.QueryString["searchKey"]);
                if (SurveyorLocation.Count == 1)
                {
                    String SurveyorLocationStr;
                    foreach (var item in SurveyorLocation)
                    {
                        SurveyorLocationStr = String.Concat(item.Id.ToString(), "|", item.Code, "|", item.Name);
                        return SurveyorLocationStr;
                    }

                }
                else if (SurveyorLocation.Count > 1)
                {
                    return "MoreOne";
                }
            }
            return "NotFound";
        }

        public ActionResult Surveyor_SurveyorLocationPopLookup()
        {
            SurveyorLocationModel model = new SurveyorLocationModel();
            if (Request.QueryString["searchKey"] != null)
            {
                model.ListOfSurveyorLocation = this.Surveyor_GetSurveyorLocationForKey(Request.QueryString["searchKey"]);
            }
            else
            {
                model.ListOfSurveyorLocation = this.Surveyor_GetSurveyorLocationAll();
            }
            return View(model);
        }

        private List<SurveyorLocationModel> Surveyor_GetSurveyorLocationForKey(String key)
        {

            var result = new List<SurveyorLocationModel>();
            var service = new ServiceClient();
            GetAllSurveyorLocationRequestDto gAllreq = new GetAllSurveyorLocationRequestDto
            {
                Code = key
            };
            var list = service.GetAllSurveyorLocation(gAllreq);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					result.Add(SurveyorLocationMapper.DtoToModel(item));
                }
            }
            return result;
        }

        private List<SurveyorLocationModel> Surveyor_GetSurveyorLocationAll()
        {
            return Surveyor_GetSurveyorLocationAll(null);
        }

        private List<SurveyorLocationModel> Surveyor_GetSurveyorLocationAll(string searchValue)
        {
            var result = new List<SurveyorLocationModel>();
            var service = new ServiceClient();
            GetAllSurveyorLocationRequestDto request = null;
            if (!String.IsNullOrEmpty(searchValue))
            {
                request = new GetAllSurveyorLocationRequestDto()
                {
													
																			
																			
																			
													Code = searchValue,
																			
													Name = searchValue,
																			
											
                    Sort = "Code", // ยังไม่ได้เปลี่ยนให้ Auto
                    SortType = "ASC",
                };
            }
            var list = service.GetAllSurveyorLocation(request);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					 result.Add(SurveyorLocationMapper.DtoToModel(item));
                }
            }
            return result;
        }
        #endregion

		
		#region SessionInfo_Surveyor lookup
        /* Summary
         * 1 lookup attribute has 4 method in controller
         * 
         * 1. XXXGetLookup() -> get value from search key
         * 2. XXXPopLookup() -> popup the lookup page for user selection.
         *    It will feed the model to the popup View that has the same name.
         *    (Each lookup has it own popup View)
         * 3. GetXXXForKey(string key) -> get 
         */
        public String SessionInfo_SurveyorGetLookup()
        {
            SurveyorModel model = new SurveyorModel();
            if (Request.QueryString["searchKey"] != null)
            {
                List<SurveyorModel> Surveyor = this.SessionInfo_GetSurveyorForKey(Request.QueryString["searchKey"]);
                if (Surveyor.Count == 1)
                {
                    String SurveyorStr;
                    foreach (var item in Surveyor)
                    {
                        SurveyorStr = String.Concat(item.Id.ToString(), "|", item.Code, "|", item.Name);
                        return SurveyorStr;
                    }

                }
                else if (Surveyor.Count > 1)
                {
                    return "MoreOne";
                }
            }
            return "NotFound";
        }

        public ActionResult SessionInfo_SurveyorPopLookup()
        {
            SurveyorModel model = new SurveyorModel();
            if (Request.QueryString["searchKey"] != null)
            {
                model.ListOfSurveyor = this.SessionInfo_GetSurveyorForKey(Request.QueryString["searchKey"]);
            }
            else
            {
                model.ListOfSurveyor = this.SessionInfo_GetSurveyorAll();
            }
            return View(model);
        }

        private List<SurveyorModel> SessionInfo_GetSurveyorForKey(String key)
        {

            var result = new List<SurveyorModel>();
            var service = new ServiceClient();
            GetAllSurveyorRequestDto gAllreq = new GetAllSurveyorRequestDto
            {
                Code = key
            };
            var list = service.GetAllSurveyor(gAllreq);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					result.Add(SurveyorMapper.DtoToModel(item));
                }
            }
            return result;
        }

        private List<SurveyorModel> SessionInfo_GetSurveyorAll()
        {
            return SessionInfo_GetSurveyorAll(null);
        }

        private List<SurveyorModel> SessionInfo_GetSurveyorAll(string searchValue)
        {
            var result = new List<SurveyorModel>();
            var service = new ServiceClient();
            GetAllSurveyorRequestDto request = null;
            if (!String.IsNullOrEmpty(searchValue))
            {
                request = new GetAllSurveyorRequestDto()
                {
													
																			
																			
																			
																			
																			
													Name = searchValue,
																			
																			
																			
																			
																			
													Code = searchValue,
																			
											
                    Sort = "Code", // ยังไม่ได้เปลี่ยนให้ Auto
                    SortType = "ASC",
                };
            }
            var list = service.GetAllSurveyor(request);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					 result.Add(SurveyorMapper.DtoToModel(item));
                }
            }
            return result;
        }
        #endregion

		
		#region SessionInfo_Customer lookup
        /* Summary
         * 1 lookup attribute has 4 method in controller
         * 
         * 1. XXXGetLookup() -> get value from search key
         * 2. XXXPopLookup() -> popup the lookup page for user selection.
         *    It will feed the model to the popup View that has the same name.
         *    (Each lookup has it own popup View)
         * 3. GetXXXForKey(string key) -> get 
         */
        public String SessionInfo_CustomerGetLookup()
        {
            CustomerModel model = new CustomerModel();
            if (Request.QueryString["searchKey"] != null)
            {
                List<CustomerModel> Customer = this.SessionInfo_GetCustomerForKey(Request.QueryString["searchKey"]);
                if (Customer.Count == 1)
                {
                    String CustomerStr;
                    foreach (var item in Customer)
                    {
                        CustomerStr = String.Concat(item.Id.ToString(), "|", item.Code, "|", item.Name);
                        return CustomerStr;
                    }

                }
                else if (Customer.Count > 1)
                {
                    return "MoreOne";
                }
            }
            return "NotFound";
        }

        public ActionResult SessionInfo_CustomerPopLookup()
        {
            CustomerModel model = new CustomerModel();
            if (Request.QueryString["searchKey"] != null)
            {
                model.ListOfCustomer = this.SessionInfo_GetCustomerForKey(Request.QueryString["searchKey"]);
            }
            else
            {
                model.ListOfCustomer = this.SessionInfo_GetCustomerAll();
            }
            return View(model);
        }

        private List<CustomerModel> SessionInfo_GetCustomerForKey(String key)
        {

            var result = new List<CustomerModel>();
            var service = new ServiceClient();
            GetAllCustomerRequestDto gAllreq = new GetAllCustomerRequestDto
            {
                Code = key
            };
            var list = service.GetAllCustomer(gAllreq);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					result.Add(CustomerMapper.DtoToModel(item));
                }
            }
            return result;
        }

        private List<CustomerModel> SessionInfo_GetCustomerAll()
        {
            return SessionInfo_GetCustomerAll(null);
        }

        private List<CustomerModel> SessionInfo_GetCustomerAll(string searchValue)
        {
            var result = new List<CustomerModel>();
            var service = new ServiceClient();
            GetAllCustomerRequestDto request = null;
            if (!String.IsNullOrEmpty(searchValue))
            {
                request = new GetAllCustomerRequestDto()
                {
													
																			
																			
																			
													Name = searchValue,
																			
																			
																			
																			
																			
																			
																			
																			
																			
																			
													Code = searchValue,
											
                    Sort = "Code", // ยังไม่ได้เปลี่ยนให้ Auto
                    SortType = "ASC",
                };
            }
            var list = service.GetAllCustomer(request);
            if (list.Data != null && list.Data.Count > 0)
            {
                foreach (var item in list.Data)
                {
					 result.Add(CustomerMapper.DtoToModel(item));
                }
            }
            return result;
        }
        #endregion

		    }
}